﻿namespace question6
{
    public class Animal
    {
        public virtual void Voice()
        {
        }
    }
    public class Cat : Animal
    {
        public override void Voice()
        {
            Console.WriteLine("猫：喵喵叫");
        }
    }
    public class Pig : Animal
    {
        public override void Voice()
        {
            Console.WriteLine("猪：哼哼叫");
        }
    }
    public class Dog : Animal
    {
        public override void Voice()
        {
            Console.WriteLine("狗：汪汪叫");
        }
    }
    public class Store
    {
        public Animal GetInstance(string animalType)
        {
            string type = animalType.ToLower();

            switch (type)
            {
                case "dog":
                    return new Dog();
                case "pig":
                    return new Pig();
                default:
                    return new Cat();
            }
        }
    }
    public class Program
    {
        public static void Main()
        {
            Store petStore = new Store();
            Animal dog = petStore.GetInstance("dog");
            Animal pig = petStore.GetInstance("pig");
            Animal cat1 = petStore.GetInstance("cat");
            Animal cat2 = petStore.GetInstance("bird"); 
            dog.Voice();
            pig.Voice();
            cat1.Voice();
            cat2.Voice();
        }
    }
}
